package com.cysion.study.ui

import android.content.Intent
import android.net.Uri
import android.text.TextUtils
import android.view.View
import com.cysion.study.ktbox.base.BaseActivity
import com.cysion.study.ktbox.net.BaseResponseRx
import com.cysion.study.ktbox.net.ErrorHandler
import com.cysion.study.ktbox.utils.CLog
import com.cysion.study.ktbox.utils.whiteTextTheme
import com.cysion.other.color
import com.cysion.targetfun._subscribe
import com.cysion.study.uibox.dialog.Alert
import com.cysion.study.uibox.dialog.AlertSearch
import com.cysion.study.uibox.dialog.CONFIRM
import com.cysion.study.R
import com.cysion.study.helper.UserCache
import com.cysion.study.net.ApiClient
import com.cysion.study.widget.ShowToast
import kotlinx.android.synthetic.main.activity_tenancy_detail.*

//租用列表
class TenancyDetailActivity : BaseActivity(), View.OnClickListener {


    override fun getLayoutId(): Int = R.layout.activity_tenancy_detail

    override fun initView() {
        whiteTextTheme(color(R.color.main_cl))
        tv_submit.setOnClickListener(this)
        iv_call.setOnClickListener(this)

    }
    override fun onClick(v: View?) {
        when (v?.id) {
            R.id.iv_call->{
                //拨打电话
                val intent = Intent()
                intent.action = Intent.ACTION_DIAL//dial是拨号的意思
                intent.data = Uri.parse("tel:" + "13800138000")//这个tel不能改，后面的数字可以随便改
                startActivity(intent)
            }
            R.id.tv_submit->{//弹窗搜索
                AlertSearch.search(self,""){ confirm: Int, start: String, end: String ->
                    CLog.i("@@@搜索"+start+end)
//                        getDataList(curPage,start,end)
                    Alert.payType(self,"","","","确定"){confirm, type->
                        if (TextUtils.isEmpty(type)) {
                            ShowToast("请选择支付方式")
                            return@payType
                        }
                        if (confirm == CONFIRM) {
                            //1支付宝  2微信
                            if (type == "1") {
//                                submit(money)
                                ShowToast("支付宝支付")
                            }else if (type == "2") {
                                ShowToast("微信支付")
                            }
                        }
                    }                }
            }
        }
    }
    //加载数据
    override fun initData() {
        super.initData()

    }



    private fun getDataList(page: Int) {
        Alert.loading(self)
        ApiClient.api.getTutorOrderList(UserCache.token,"","").compose(BaseResponseRx.validateToMain())
            ._subscribe {
                _onNext {
                    Alert.close()

                    /*if (curPage == 1) {
                        dataList.clear()
                        if (dataList.size == 0) {
                            multiView.showEmpty()
                        }
                    }
                    if (it.size <= 0) {
                        smartLayout.setEnableLoadMore(false)
                    } else {
                        curPage++
                        dataList.addAll(it)
                        dataAdapter.notifyDataSetChanged()
                        multiView.showContent()
                    }*/
                }
                _onError {
                    Alert.close()
                    ShowToast(ErrorHandler.handle(it).errorMsg)

                }
            }

    }

    private fun dowith(orderId: String, type: String, reason: String) {
        Alert.loading(self)
        ApiClient.api.dowith(UserCache.token, orderId, type, reason).compose(BaseResponseRx.validateToMain())
            ._subscribe {
                _onNext {
                    Alert.close()
                    ShowToast("操作成功")

                }
                _onError {
                    Alert.close()
                    ShowToast(ErrorHandler.handle(it).errorMsg)
                }
            }

    }


    override fun closeMvp() {
    }

}
